﻿using System.Web.Mvc;
using Journal.Front.Presentation.FilterAttributes;
using Journal.Front.Presentation.Models.AccountModels;
using Journal.Front.Presentation.PresentationServicesInterfaces;

namespace Journal.Front.Presentation.Controllers
{
    public class AccountController : Controller
    {
        private readonly IAccountPresentationService accountPresentationService;

        public AccountController(IAccountPresentationService accountPresentationService)
        {
            this.accountPresentationService = accountPresentationService;
        }

        [HttpGet]
        public ActionResult LogOn()
        {
            AccountModel model = accountPresentationService.CreateAccountModel();
            return View(model);
        }

        public ActionResult Registration()
        {
            return View("../Slicing/Registration");
        }

        public ActionResult FoggotPassword()
        {
            return View("../Slicing/FoggotPassword");
        }

        [HttpPost]
        public ActionResult LogOn(AccountModel model)
        {
            if(ModelState.IsValid)
            {
                bool isLogOn = accountPresentationService.LogOn(model);
                if(isLogOn)
                {
                    return RedirectToAction("Index", "StudyRoom");
                }

                return View(model);
            }

            return View(model);
        }
    }
}